package com.lq.ecoldchain.ui.mine.verified

import android.arch.lifecycle.MutableLiveData
import com.lq.ecoldchain.base.viewmodel.BaseViewModel
import com.lq.ecoldchain.internet.BaseObserver
import com.lq.ecoldchain.util.logd
import com.lq.ecoldchain.util.logi
import com.lq.ecoldchain.util.logw
import com.lq.ecoldchain.util.toast

/*
*2018/12/27 0027  17:17
*function by lq
*/
class VerifiedViewModel : BaseViewModel() {
    val name by lazy { MutableLiveData<String>() }
    val phone by lazy { MutableLiveData<String>() }

    val positive by lazy { MutableLiveData<String>() }
    val back by lazy { MutableLiveData<String>() }

    val isSuccess by lazy { MutableLiveData<Boolean>() }
    private val map by lazy { HashMap<String, String>() }

    fun commit() {
        when (name.value.isNullOrEmpty() || phone.value.isNullOrEmpty() || positive.value.isNullOrEmpty() || back.value.isNullOrEmpty()) {
            true -> {
                toast { "请填写完整信息" }
            }
            false -> {
                //验证个人身份证
                map.clear()
                map["name"] = name.value!!
                map["certificationNo"] = phone.value!!
                map["certificationFaceImg"] = positive.value!!
                map["certificationBackImg"] = back.value!!
                BaseNetCore.ApiServiceImpl.submitAudit(map).compose(RxTransformer.switchSchedulers()).subscribe(object : BaseObserver<String>() {
                    override fun onSuccess(t: String?) {
                        isSuccess.value = true
                    }

                    override fun onFail(code: String) {}
                })
            }
        }
    }
}